package com.tjetc.service.impl;

import com.tjetc.entity.Receives;
import com.tjetc.dao.ReceivesDao;
import com.tjetc.entity.ShoePhotos;
import com.tjetc.service.ReceivesService;
import com.tjetc.util.Pager;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 收货地址表(Receives)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:06:07
 */
@Service("receivesService")
public class ReceivesServiceImpl implements ReceivesService {
    @Resource
    private ReceivesDao receivesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param recid 主键
     * @return 实例对象
     */
    @Override
    public Receives queryById(Long recid) {
        return this.receivesDao.queryById(recid);
    }

    /**
     * 分页查询
     *
     * @param receives 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Object queryByPage(Receives receives, Integer pageNum,Integer pageSize) {
        //查询总记录条数
        Integer recordCount = receivesDao.count(receives);
        //构建分页信息对象
        Pager pager = new Pager(pageNum, pageSize, recordCount);
        //根据pager查询需要的数据
        List<Receives> list = receivesDao.queryAllByLimit(receives,pager.getStart(), pageSize);
        //将分页信息和查询到的数据一起返回到前端
        HashMap<String,Object> map = new HashMap<>();
        map.put("pager",pager);
        map.put("list",list);
        return map;
    }

    /**
     * 新增数据
     *
     * @param receives 实例对象
     * @return 实例对象
     */
    @Override
    public Receives insert(Receives receives) {
        this.receivesDao.insert(receives);
        return receives;
    }

    /**
     * 修改数据
     *
     * @param receives 实例对象
     * @return 实例对象
     */
    @Override
    public Receives update(Receives receives) {
        this.receivesDao.update(receives);
        return this.queryById(receives.getRecid());
    }

    /**
     * 通过主键删除数据
     *
     * @param recid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long recid) {
        return this.receivesDao.deleteById(recid) > 0;
    }
}
